package com.ssrs.batch.core.channel;

import com.ssrs.batch.core.factory.OpenResourceSuffixCreator;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.file.MultiResourceItemWriter;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

/**
 * 顺序写多个文件
 *
 * @author ssrs
 */
public class MultiResourceWriter<T> extends MultiResourceItemWriter<T> {
    public MultiResourceWriter() {
        super();
    }

    public MultiResourceWriter(String suffix, String path) {
        super();
        setResource(getResource(path));
        setResourceSuffixCreator(new OpenResourceSuffixCreator(suffix));
    }

    @Override
    public void open(ExecutionContext executionContext) throws ItemStreamException {
        super.open(executionContext);
    }

    private Resource getResource(String path) {
        FileSystemResource fileSystemResource = new FileSystemResource(path);
        return fileSystemResource;
    }

    @Override
    public void update(ExecutionContext executionContext) throws ItemStreamException {
        super.update(executionContext);
    }
}

